//package com.iflytek.cosmo.ocr.common.config;
//
//import com.iflytek.cosmo.ocr.common.core.SpringContextUtil;
//import com.iflytek.sec.uap.cache.session.RedisSessionMappingStorage;
//import com.iflytek.sec.uap.client.rest.filter.AuthenticationFilter;
//import com.iflytek.sec.uap.client.rest.filter.Cas20ProxyReceivingTicketValidationFilter;
//import com.iflytek.sec.uap.client.rest.filter.DecisionFilter;
//import com.iflytek.sec.uap.client.rest.filter.FilterChainProxy;
//import com.iflytek.sec.uap.client.rest.listener.SpringStartListener;
//import org.jasig.cas.client.util.HttpServletRequestWrapperFilter;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.web.servlet.FilterRegistrationBean;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.DependsOn;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 包名com.iflytek.cosmo.ocr.common.config
// * 类名FilterConfig
// * 当前系统用户taowang7
// * 邮箱：taowang7@iflytek.com
// * 日期2020/9/22
// * 16:40
// * 项目名view-ocr-server
// */
//@Configuration
//public class FilterConfig {
//    @Value("${cas.server.context}")
//    private String serverContext;
//
//    @Value("${cas.server.login:login}")
//    private String serverLogin;
//
//    @Value("${cas.client.context}")
//    private String clientContext;
//
//    @Value("${spring.session.store-type}")
//    private String sessionStoreType;
//
//    @Bean
//    public SpringContextUtil springContextUtil(ApplicationContext applicationContext) {
//        SpringContextUtil springContextUtil = new SpringContextUtil();
//        springContextUtil.setApplicationContext(applicationContext);
//        return springContextUtil;
//    }
//
//    @Bean
//    public SpringStartListener springStartListener() {
//        SpringStartListener springStartListener = new SpringStartListener();
//        return springStartListener;
//    }
//
//    @Bean
//    public HttpServletRequestWrapperFilter httpServletRequestWrapperFilter() {
//        return new HttpServletRequestWrapperFilter();
//    }
//
//    @Bean
////        @DependsOn({ "memoryConfigUtil","memoryConfig", "springContextUtil","uapConfigUtil" })
//    @DependsOn({ "memoryConfig", "springContextUtil" })
//    public FilterRegistrationBean uapFilterRegistration() {
//        // 负责对请求进行登录验证拦截
//        AuthenticationFilter authenticationFilter = new AuthenticationFilter();
//        authenticationFilter.setCasServerLoginUrl(serverContext + serverLogin);
//        authenticationFilter.setServerName(clientContext);
//
//        // 负责对请求参数ticket进行验证
//        Cas20ProxyReceivingTicketValidationFilter validationFilter = new Cas20ProxyReceivingTicketValidationFilter();
//        validationFilter.setUseSession(true);
//        validationFilter.setServerName(clientContext);
//        validationFilter.setRedirectAfterValidation(true);
//        validationFilter.setMillisBetweenCleanUps(60000);
//
//        // 支持getUserPrincipal，getRemoteUser方法来取得用户信息
//        HttpServletRequestWrapperFilter httpServletRequestWrapperFilter = new HttpServletRequestWrapperFilter();
//
//        // 访问决策
//        DecisionFilter decisionFilter = new DecisionFilter();
//
//        // 过滤器链代理初始化
//        FilterChainProxy uapClientFilter = new FilterChainProxy();
//        uapClientFilter.setHttpServletRequestWrapperFilter(httpServletRequestWrapperFilter);
//        uapClientFilter.setValidationFilter(validationFilter);
//        uapClientFilter.setAuthenticationFilter(authenticationFilter);
//        uapClientFilter.setDecisionFilter(decisionFilter);
//
//        // 启用redis或者内存
//        if(sessionStoreType.equals("redis"))  {
//            ApplicationContext applicationContext = SpringContextUtil.getApplicationContext();
//            RedisSessionMappingStorage sessionMappingStorage = (RedisSessionMappingStorage) applicationContext.getBean("sessionMappingStorage");
//            uapClientFilter.setSessionMappingStorage(sessionMappingStorage);
//        }
//
//        // 注册过滤器链代理
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        registration.setFilter(uapClientFilter);
//        registration.setName("uapClientFilter");
//        Map<String, String> initParameters = new HashMap<String, String>();
//        initParameters.put("targetFilterLifecycle", "true");
//        registration.setInitParameters(initParameters);
//        registration.addUrlPatterns("/*");
//        registration.setOrder(1);
//        return registration;
//    }
//}
